package com.vnet.bdz.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.XTemplate;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.data.XmlReader;
import com.gwtext.client.widgets.BoxComponent;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.DataView;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.event.DataViewListener;

public class Galeria implements EntryPoint {

	final DataView galeriaView = new DataView("div.galeria");
	@Override
	public void onModuleLoad() {
		try {
			setupGaleries();
			RootPanel.get("listaGaleri").add(galeriaView);
		} catch (Exception e) {
			MessageBox.alert(e.getMessage());
			
		}
	}
	
	private void setupGaleries() {
        XmlReader reader = new XmlReader("item", new RecordDef(   
                new FieldDef[]{   
                        new StringFieldDef("description","/description"),
                        new StringFieldDef("title","/title"),
                        new StringFieldDef("icon","/icon"),
                        new StringFieldDef("content","/content")
                }   
        ));   
        
        SiteServiceAsync siteService = GWT.create(SiteService.class);
        final Store store = new Store(reader);
        galeriaView.setStore(store);

        final XTemplate wtemplate = new XTemplate(new String[]{   
        		"<table class='galariatab'><tpl for='.'>",
        		"<tr><td><div class='galeria'>",
        		"<span class='header'>{title}</span><br>",
        		"<span class='description'><img src='{icon}' ext:qtip='{title}'>{description}</span>",
                "</div></td></tr>",
                "</tpl></table>"});  


    
        galeriaView.setTpl(wtemplate);

        AsyncCallback<String> callback = new AsyncCallback<String>() 
        {
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
			}

			@Override
			public void onSuccess(String result) {
				try
				{
					store.loadXmlData(result, false);
				} catch (Exception e) {
					MessageBox.alert(e.getMessage());
				}
			}  
        };
        
        siteService.getPicasaAlbumsRSSXML("http://picasaweb.google.com/data/feed/base/user/klub.biegacza.katy.wroclawskie?alt=rss&kind=album&hl=pl",callback);

	}
}
